import { ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY } from '@/constants';

export function getAccessToken(): string {
  return localStorage.getItem(ACCESS_TOKEN_KEY) || '';
}

export function getRefreshToken(): string {
  return localStorage.getItem(REFRESH_TOKEN_KEY) || '';
}

export function setToken(token: API.Token) {
  if (token.accessToken) {
    localStorage.setItem(ACCESS_TOKEN_KEY, token.accessToken);
  } else {
    localStorage.removeItem(ACCESS_TOKEN_KEY);
  }
  if (token.refreshToken) {
    localStorage.setItem(REFRESH_TOKEN_KEY, token.refreshToken);
  } else {
    localStorage.removeItem(REFRESH_TOKEN_KEY);
  }
}

export function removeToken() {
  localStorage.removeItem(ACCESS_TOKEN_KEY);
  localStorage.removeItem(REFRESH_TOKEN_KEY);
}
